package Multithreading.Exercise004;

/**
 * ClassName:MyThread
 * Package:Multithreading.Exercise004
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/3/6-21:51
 * @Version:v1.0
 */
public class MyThread extends Thread{
    static int ticket =0;
    static Object obj = new Object();
    @Override
    public void run() {
        while (true){
            synchronized (obj){
                if (ticket<1000){
                    try {
                        Thread.sleep(3);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticket++;
                    System.out.println(getName()+"正在卖第"+ticket+"张票！！");
                }else {
                    break;
                }
            }

        }

    }
}
